package T0;

import java.util.HashMap;

/**
 * @Author cheng.song
 * @create 2022/2/24 11:14
 */
public class T1两数之和 {

    public static void main(String[] args) {
        int[] nums = new int[]{2,7,11,15};
        System.out.println(twoSum(nums,9));
        for (int i = 0; i < twoSum(nums, 9).length; i++) {
            System.out.println(i);
        }
    }

    public static int[] twoSum(int[] nums, int target) {
        HashMap map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if (map.get(target - nums[i]) != null) {
                return new int[]{i, (int) map.get(target - nums[i])};
            }else{
                map.put(nums[i],i);
            }
        }
        return null;
    }


}
